//
//  LKSchedleDetailViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/5/2.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKSchedleDetailViewController.h"
#import "LKHomeNoticeDetailCell.h"
#import "LKContentLabelCell.h"
@interface LKSchedleDetailViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)LKBaseTableview *tableview;
@property(nonatomic,strong)UIImage *bluepot;
@property(nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation LKSchedleDetailViewController
-(LKBaseTableview *)tableview{
    if (!_tableview) {
        _tableview = [LKBaseTableview setTableviewWithFrame:CGRectMake(0, NAVIGATION_BAR_HEIGHT, WIDTH, HEIGHT - NAVIGATION_BAR_HEIGHT) style:UITableViewStylePlain registercellClasss:@[@"LKHomeNoticeDetailCell",@"LKContentLabelCell"]];
        [self.view addSubview:_tableview];
        _tableview.delegate = self;
        _tableview.dataSource = self;
        _tableview.emptyDataSetDelegate = self;
        _tableview.emptyDataSetSource = self;
        _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableview.estimatedRowHeight = 200;
    }
    return _tableview;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self getScheduleDetailContent];
    // Do any additional setup after loading the view.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LKContentLabelCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKContentLabelCell"];
    cell.schedulModel = self.dataArray[indexPath.row];
    return cell;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    LKScheduleListModel *model = self.dataArray[section];
    UIView *headerView = [[UIView alloc] init];
    headerView.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc] init];
    [headerView addSubview:label];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = COLOR_HEX(0x565D66);
    label.font = [UIFont systemFontOfSize:17];
    label.text = model.calenderName;
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(headerView);
    }];
    return headerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 60;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    LKScheduleListModel *model = self.dataArray[section];
    UIView *footerView = [[UIView alloc] init];
    footerView.backgroundColor = [UIColor whiteColor];
    UILabel *label = [[UILabel alloc] init];
    [footerView addSubview:label];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = COLOR_HEX(0xA1A1A1);
    label.font = [UIFont systemFontOfSize:14];
    label.text = @"";
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(footerView.mas_top).offset(50);
        make.right.equalTo(footerView.mas_right).offset(-15);
        make.height.mas_equalTo(20);
    }];
    
    UILabel *label1 = [[UILabel alloc] init];
    [footerView addSubview:label1];
    label1.textAlignment = NSTextAlignmentCenter;
    label1.textColor = COLOR_HEX(0xA1A1A1);
    label1.font = [UIFont systemFontOfSize:14];
    label1.text = model.entryTimeText;
    [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).offset(10);
        make.right.equalTo(footerView.mas_right).offset(-15);
        make.height.mas_equalTo(20);
    }];
    
    return footerView;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 110;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}
/**
 获取运营公告的详情
 */
-(void)getScheduleDetailContent{
    NSDictionary *param = @{@"Id":self.shduleId};
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:homeScheduleDetailUrl header:[LKUserInforTool header] parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        LKScheduleListModel *model = [LKScheduleListModel modelWithDictionary:responseObject[@"result"]];
        [self.dataArray addObject:model];
        [self.tableview reloadData];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];

}
-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc] init];
    }
    return _dataArray;
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    self.navigationItem.title = @"日程详情";
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
